<?php
class ThuchiendecuongsController extends AppController {

	var $name = 'Thuchiendecuongs';

	function index() {
		$this->Thuchiendecuong->recursive = 0;
		$this->set('thuchiendecuongs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid thuchiendecuong', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('thuchiendecuong', $this->Thuchiendecuong->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Thuchiendecuong->create();
			if ($this->Thuchiendecuong->save($this->data)) {
				$this->Session->setFlash(__('The thuchiendecuong has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The thuchiendecuong could not be saved. Please, try again.', true));
			}
		}
		$detais = $this->Thuchiendecuong->Detai->find('list');
		$hocviens = $this->Thuchiendecuong->Hocvien->find('list');
		$dgdecuongs = $this->Thuchiendecuong->Dgdecuong->find('list');
		$this->set(compact('detais', 'hocviens', 'dgdecuongs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid thuchiendecuong', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Thuchiendecuong->save($this->data)) {
				$this->Session->setFlash(__('The thuchiendecuong has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The thuchiendecuong could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Thuchiendecuong->read(null, $id);
		}
		$detais = $this->Thuchiendecuong->Detai->find('list');
		$hocviens = $this->Thuchiendecuong->Hocvien->find('list');
		$dgdecuongs = $this->Thuchiendecuong->Dgdecuong->find('list');
		$this->set(compact('detais', 'hocviens', 'dgdecuongs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for thuchiendecuong', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Thuchiendecuong->delete($id)) {
			$this->Session->setFlash(__('Thuchiendecuong deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Thuchiendecuong was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
